package listbyorder.access201_300.test204;

/**
 * @author code_yc
 * @version 1.0
 * @date 2020/6/22 20:48
 */
public class Solution1 {

    public int countPrimes(int n) {
        if(n <= 2) return 0;
        int ans = 0;
        for(int i = 2; i < n; i++){
            if(isValid(i)){
                ans++;
            }
        }
        return ans;
    }

    private boolean isValid(int num){
        int sqrt = (int) Math.sqrt(num);
        for(int i = 2; i <= sqrt; i++){
            if(num % i == 0){
                return false;
            }
        }
        return true;
    }
}
